<?php

namespace app\admin\model\shopro\lucky;

use think\Model;


class User extends Model
{

    

    

    // 表名
    protected $name = 'shopro_lucky_user';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';


    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_lucky_text',
        'stutas_text'
    ];
    

    
    public function getIsLuckyList()
    {
        return ['0' => __('Is_lucky 0'), '1' => __('Is_lucky 1'), '2' => __('Is_lucky 2')];
    }

    public function getStutasList()
    {
        return ['0' => __('Stutas 0'), '1' => __('Stutas 1')];
    }


    public function getIsLuckyTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_lucky']) ? $data['is_lucky'] : '');
        $list = $this->getIsLuckyList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStutasTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['stutas']) ? $data['stutas'] : '');
        $list = $this->getStutasList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function userinfo()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function server()
    {
        return $this->belongsTo('Server', 'lucky_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function goods()
    {
        return $this->belongsTo('app\admin\model\shopro\goods\Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
